import org.gradle.api.DefaultTask
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

class ProvideBuildClasspathTask extends DefaultTask {
    @OutputFile File outFile

    @TaskAction
    public void writeProperties() throws Exception {
        final Properties props = new Properties()

        AndroidSdk.ALL_SDKS.each { androidSdk ->
            def config = project.configurations.create("sdk${androidSdk.apiLevel}")
            project.dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.coordinates)
            props.setProperty(androidSdk.coordinates, config.files.join(File.pathSeparator))
        }

        File outDir = outFile.parentFile
        if (!outDir.directory) outDir.mkdirs()
        outFile.withPrintWriter { out ->
            props.store(out, "# GENERATED by ${this} -- do not edit")
        }
    }
}
